package com.ruoyi.index_message.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.index_message.domain.IndexMessageInfo;
import com.ruoyi.index_message.service.IIndexMessageInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页资讯Controller
 * 
 * @author zbz
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/index_message/info")
public class IndexMessageInfoController extends BaseController
{
    @Autowired
    private IIndexMessageInfoService indexMessageInfoService;

    /**
     * 查询首页资讯列表
     */
    @PreAuthorize("@ss.hasPermi('index_message:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(IndexMessageInfo indexMessageInfo)
    {
        startPage();
        List<IndexMessageInfo> list = indexMessageInfoService.selectIndexMessageInfoList(indexMessageInfo);
        return getDataTable(list);
    }

    /**
     * 导出首页资讯列表
     */
    @PreAuthorize("@ss.hasPermi('index_message:info:export')")
    @Log(title = "首页资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IndexMessageInfo indexMessageInfo)
    {
        List<IndexMessageInfo> list = indexMessageInfoService.selectIndexMessageInfoList(indexMessageInfo);
        ExcelUtil<IndexMessageInfo> util = new ExcelUtil<IndexMessageInfo>(IndexMessageInfo.class);
        util.exportExcel(response, list, "首页资讯数据");
    }

    /**
     * 获取首页资讯详细信息
     */
    @PreAuthorize("@ss.hasPermi('index_message:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(indexMessageInfoService.selectIndexMessageInfoById(id));
    }

    /**
     * 新增首页资讯
     */
    @PreAuthorize("@ss.hasPermi('index_message:info:add')")
    @Log(title = "首页资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndexMessageInfo indexMessageInfo)
    {
        return toAjax(indexMessageInfoService.insertIndexMessageInfo(indexMessageInfo));
    }

    /**
     * 修改首页资讯
     */
    @PreAuthorize("@ss.hasPermi('index_message:info:edit')")
    @Log(title = "首页资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndexMessageInfo indexMessageInfo)
    {
        return toAjax(indexMessageInfoService.updateIndexMessageInfo(indexMessageInfo));
    }

    /**
     * 删除首页资讯
     */
    @PreAuthorize("@ss.hasPermi('index_message:info:remove')")
    @Log(title = "首页资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(indexMessageInfoService.deleteIndexMessageInfoByIds(ids));
    }
}
